package us.versus.them.hmap;

import flash.display.DisplayObject;

class MultipleLoader {
	var onComplete : String -> Hash< DisplayObject > -> Void;
	var name : String;
    var count : Int;
	var displayObjects : Hash< DisplayObject >;

	public function new( name : String ) {
		this.setName( name );
	}

	public function getName() : String {
		return this.name;
	}

	public function setName( name : String ) {
		this.name = name;
	}

	public function load( uris : Array< String >, onComplete : String -> Hash< DisplayObject > -> Void  ) : Void {
		this.onComplete = onComplete;
		this.count = uris.length;
		this.displayObjects = new Hash< DisplayObject >();
		for ( uri in uris ) {
			( new UriLoader( uri ) ).load( onLoad );
		}
	}

	public function onLoad( name : String, displayObject : DisplayObject ) { 
		this.displayObjects.set( name, displayObject );
		this.count--;
        if ( 0 == this.count ) {
            this.onComplete( this.getName(), this.displayObjects );
        }
    }
}
